package com.example.app.base

import android.content.Intent
import android.os.Bundle
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.util.LogUtils
import com.weikaiyun.fragmentation.SupportHelper

abstract class BaseSupportActivity<VB : ViewBinding> : BaseActivity() {

    protected var mViewBinding: VB? = null

    abstract fun getViewBinding(): VB?

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewBinding = getViewBinding()
        mViewBinding?.apply { setContentView(root) }
    }

    override fun onDestroy() {
        super.onDestroy()
        mViewBinding = null
    }

    @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        LogUtils.d("${getLogTag()},requestCode=$requestCode resultCode=$resultCode data=$data")

        val listFragment = SupportHelper.getActiveFragments(supportFragmentManager)
        listFragment.forEach {
            if (it is BaseFragment) {
                LogUtils.w("${getLogTag()},传递 name=${it.javaClass.simpleName}")
                it.onActivityResult(requestCode, resultCode, data)
            }
        }
    }
}